<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/jsp/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>信息编辑窗体</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico"> <link href="${ctxStatic}/plugins/h+/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/resources/plugins/h+/css/plugins/jsTree/style.min.css" rel="stylesheet">
    <style>
        .jstree-open>.jstree-anchor>.fa-folder:before{content:"\f07c"}.jstree-default .jstree-icon.none{width:0}
    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">

                <div class="ibox-content">
                    <form onsubmit="return  false" class="form-horizontal m-t" id="cardTypeForm">
                        <input id="id" value="${cardType.id}" name="id" type="hidden">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">名称：</label>
                            <div class="col-sm-8">
                                <input id="name" value="${cardType.name}" name="name" class="form-control" type="text">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">返币比例：</label>
                            <div class="col-sm-8">
                                <input id="percentage" style="width: 95%;display: inline;" placeholder="请输入0-100的数字,如:5.5即代表5.5%" value="${cardType.percentage}" name="percentage" class="form-control" type="number" min="0" max="100">
                                %
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">是否仅限首次获取久零券使用：</label>
                            <input type="hidden" value="${cardType.isFirst}" id="isFirstValue" name="isFirst">
                            <div class="col-sm-3">
                                <div class="switch">
                                    <div class="onoffswitch">
                                        <input type="checkbox" class="onoffswitch-checkbox" onchange="doChangeFirst()"  id="isFirst" >
                                        <label class="onoffswitch-label" for="isFirst">
                                            <span class="onoffswitch-inner"></span>
                                            <span class="onoffswitch-switch"></span>
                                        </label>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <input type="submit" class="btn btn-primary" value="提交" >
                                <%--<button id="btn_close"  class="btn btn-primary" type="button" data-dismiss="modal">关闭</button>--%>
                              <%--  <button id="transmit"  class="btn btn-primary" type="button">给父页面传值</button>--%>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/jquery.min.js?v=2.1.4"></script>
    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/content.min.js?v=1.0.0"></script>
    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/plugins/validate/jquery.validate.min.js"></script>
    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/plugins/validate/messages_zh.min.js"></script>
    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/demo/form-validate-demo.min.js"></script>

    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/plugins/jsTree/jstree.js"></script>
    <script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>

<script>
var index = parent.layer.getFrameIndex(window.name);
var areaData;

$(function () {
    if("${cardType.isFirst}"=='1'){
        $("#isFirst").prop("checked",true)
    }else{
        $("#isFirst").prop("checked",false);
        $("#isFirstValue").val(0);
    }
    $("#cardTypeForm").validate({
        submitHandler : function() {
            doSubmit();
        },
        rules:{
            name:{
                required:true,
                maxlength:50
            },
            percentage:{
                required:true
            },
            isFirst:{
                required:true
            }

        },
        messages:{
            name:{
                required:"*必填！",
                maxlength:"*长度不能超过50位！",
            },
            percentage:{
                required:"*必填！"
            } ,
            isFirst:{
                required:"*必填！"
            }
        },
        //是否在获取焦点时验证
        onfocusout:true,
        //是否在敲击键盘时验证
        //onkeyup:false,
        //提交表单后，（第一个）未通过验证的表单获得焦点
        focusInvalid:false,
        //当未通过验证的元素获得焦点时，移除错误提示
        focusCleanup:false,
    });

});

function  doChangeFirst() {
    if($("#isFirst").is(':checked')==true)
    {
        $("#isFirstValue").val(1);
    }else {
        $("#isFirstValue").val(0);
    }
}
function doSubmit()
{
    $.ajax( {
        url:'${pageContext.request.contextPath}/cardType/doSave.ac',// 跳转到 action
        data:$("#cardTypeForm").serialize(),
        type:'post',
        cache:false,
        dataType:'json',
        success:function(data) {
           if(data.success==true) {
               alert("操作成功！");
               parent.layer.close(index);
//               parent.$('#exampleTablePagination').bootstrapTable('refresh');
//               $(parent.window.frames["iframe8"].document).find("#exampleTablePagination").bootstrapTable('refresh');

           }else {
               alert("操作失败!");
           }
        },
        error : function() {
            alert("操作失败！");
        }
    });
}
</script>

</body>

</html>

